//
//  ViewController.m
//  sqlite封装
//
//  Created by lianglibao on 2018/1/15.
//  Copyright © 2018年 梁立保. All rights reserved.
//

#import "ViewController.h"
#import "Classes/MMSqliteModelTool.h"
#import "Classes/MMSqliteTool.h"
#import "MMStu.h"

@interface ViewController ()
@property (weak, nonatomic) NSString *testName;
@property (weak, nonatomic) MMStu *stu;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    MMStu *stu = [[MMStu alloc] init];
    stu.stuNum = 1;
    stu.name = @"llC";
    stu.age = 21;
    stu.score =  101;
    stu.score2 = 100;
    NSString *uid = @"123";
    NSString *name = @"qwwewerthgokdkajcjsasdggkkasmdsnjcsaskdjk";
//    NSString *name = NSString.alloc.init;
    self.testName = name;
    self.stu = stu;
    
    MMStu *stu2 = [[MMStu alloc] init];
    stu2.stuNum = 2;
    stu2.name = @"lld";
    stu2.age = 22;
    stu2.score =  102;
    stu2.score2 = 101;
    [MMSqliteModelTool saveModel:stu withuid:uid successBlock:^(BOOL isSuccess) {
        if (isSuccess) {
            return;
        }
    }];
    [MMSqliteModelTool saveModel:stu2 withuid:uid successBlock:^(BOOL isSuccess) {
        if (isSuccess) {
            return;
        }
    }];
//    BOOL isSuccess = [MMSqliteModelTool updateTable:MMStu.class uid:uid];
    
//    NSMutableArray *tableInfo = [MMSqliteTool querySql:[NSString stringWithFormat:@"select * from %@", NSStringFromClass(MMStu.class)] uid:uid];
    NSMutableArray *tableInfo = [MMSqliteTool querySql:[NSString stringWithFormat:@"pragma table_info(%@)", NSStringFromClass(MMStu.class)] uid:uid];
    __block NSString *primaryKey = @"";
    [tableInfo enumerateObjectsUsingBlock:^(NSDictionary *obj,
                                            NSUInteger idx,
                                            BOOL * _Nonnull stop) {
        if ([obj[@"pk"] intValue] == 1) {
            primaryKey = obj[@"name"];
        }
    }];
    // pragma table_info ('tablename')
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
